package metalink.admin;
import com.opensymphony.xwork2.ActionSupport;
import java.util.*;
import java.sql.*;

import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import vo.*;
import vo.mixed.*;
import model.admin.*;
import myutil.*;


public class SendInvitation_Batch extends ActionSupport{
	int[] start_years;
	public int[] getBatch_id() {
		return batch_id;
	}
	public void setBatch_id(int[] batch_id) {
		this.batch_id = batch_id;
	}
	public int[] getDepartment_id() {
		return department_id;
	}
	public void setDepartment_id(int[] department_id) {
		this.department_id = department_id;
	}
	public ArrayList<String> getReceiver_ids() {
		return receiver_ids;
	}
	public void setReceiver_ids(ArrayList<String> receiver_ids) {
		this.receiver_ids = receiver_ids;
	}
	int[] batch_id;
	int[] department_id;
	String students_staff_emails="";
	public String getStudents_staff_emails() {
		return students_staff_emails;
	}
	public void setStudents_staff_emails(String students_staff_emails) {
		this.students_staff_emails = students_staff_emails;
	}
	ArrayList<String> receiver_ids=new ArrayList<String>();
	ResultSet rs;
	HttpSession session=ServletActionContext.getRequest().getSession();
	int event_id=Integer.parseInt(session.getAttribute("event_id").toString());
public int[] getStart_years() {
		return start_years;
	}
	public void setStart_years(int[] start_years) {
		this.start_years = start_years;
	}
public String batch() throws Exception{
	Connect c = new Connect();
	receiver_ids=new ArrayList<String>();
	if (start_years != null) 
	{
		for (int start_year : start_years) 
		{
			rs = c.getResult("select * from student_details sd,student_batch sb where sd.student_id=sb.student_id and sb.start_year='"+ start_year + "'");
			while (rs.next()) 
			{
				// StudentDetailsVo single_object=new
				// StudentDetailsVo();
				receiver_ids.add(rs.getString("email_id"));
				// students_list.add(single_object);

			}
		}
		System.out.println("i am here and my size is "+receiver_ids.size()+receiver_ids.get(0)+event_id);
	}
	new SendInvitationMo().sendInvitation(receiver_ids,event_id);
 return SUCCESS;
}

public String degree_batch() throws Exception{
	Connect c = new Connect();
	receiver_ids=new ArrayList<String>();
	
	if (batch_id != null) 
	{
		
		for (int single_batch_id : batch_id) 
		{
			rs = c.getResult("select * from student_details sd,student_batch sb where sd.student_id=sb.student_id and sb.batch_id='"
					+ single_batch_id + "'");
			while (rs.next()) 
			{
				// StudentDetailsVo single_object=new
				// StudentDetailsVo();
				receiver_ids.add(rs.getString("email_id"));
				// students_list.add(single_object);

			}
		}
	}
	new SendInvitationMo().sendInvitation(receiver_ids,event_id);
	
 return SUCCESS;
}
public String specialization() throws Exception
{
	Connect c=new Connect();
	if (department_id != null) 
	{
		
		for (int single_department_id : department_id) 
		{
			rs = c.getResult("select * from student_details sd,student_batch sb,degree_department dd,department_details dde where sb.student_id=sd.student_id and sb.degree_department_id=dd.degree_department_id and dd.department_id=dde.department_id and dde.department_id='"+ single_department_id + "'");
			while (rs.next()) 
			{
				// StudentDetailsVo single_object=new
				// StudentDetailsVo();
				receiver_ids.add(rs.getString("email_id"));
				// students_list.add(single_object);

			}
		}
	}
	new SendInvitationMo().sendInvitation(receiver_ids,event_id);
	return SUCCESS;
}

public String individuals(){
	
	try {
		receiver_ids=new ArrayList<String>();
		System.out.println(students_staff_emails);
		String[] str=students_staff_emails.split(";");
		for(String single:str){
			receiver_ids.add(single);
		}
		new SendInvitationMo().sendInvitation(receiver_ids,event_id);
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		return ERROR;
	}
	return SUCCESS;
}

}
